// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import {getRequest} from './util/api'
import {postRequest} from './util/api'
import {postFormRequest} from './util/api'
import {deleteRequest} from './util/api'
import {putRequest} from './util/api'
import {initMenu} from './util/utils'
import store from './store'

Vue.config.productionTip = false

Vue.use(ElementUI);

Vue.prototype.getRequest = getRequest;
Vue.prototype.postRequest = postRequest;
Vue.prototype.postFormRequest = postFormRequest;
Vue.prototype.deleteRequest = deleteRequest;
Vue.prototype.putRequest = putRequest;

//路由守卫，所有路由访问之前都经过此函数
router.beforeEach((to, from, next)=> {
    if (to.name == 'Login') {
      next();
      return;
    }
    var user = store.state.user;
    if (null == user) {
      next({path: '/login'});
    } else {
      initMenu(router, store);
      next();
    }
  }
)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,//使用store
  components: { App },
  template: '<App/>'
})
